local M = {}

-- Modes
--   normal_mode = "n",
--   insert_mode = "i",
--   visual_mode = "v",
--   visual_block_mode = "x",
--   term_mode = "t",
--   command_mode = "c",


local keys = lvim.keys
-- 封装快捷键映射函数
function M.imap(key, action)
  keys.insert_mode[key] = action
end

function M.nmap(key, action)
  keys.normal_mode[key] = action
end

function M.vmap(key, action)
  keys.visual_mode[key] = action
end

function M.cmap(key, action)
  keys.command_mode[key] = action
end

function M.xmap(key, action)
  keys.visual_block_mode[key] = action
end

---按键映射
---@param modes string[]
---@param key string
---@param action string|table|function
M.map = function(modes, key, action)
  for _, mode in ipairs(modes) do
    if mode == "n" then
      M.nmap(key, action)
    elseif mode == "i" then
      M.imap(key, action)
    elseif mode == "v" then
      M.vmap(key, action)
    elseif mode == "c" then
      M.cmap(key, action)
    elseif mode == "x" then
      M.xmap(key, action)
    end
  end
end

return M
